package pap.bodies;

import pap.Point;
import pap.Vector;
import pap.utils.Constants;

public class SimpleBody extends Body {

	private double radius;

	public SimpleBody(double mass, Point startPosition, Vector startSpeed) {

		this.mass = mass;
		this.speed = startSpeed;
		this.massCenter = startPosition;
		if (mass > 1000)
			radius = 20;
		else
			radius = mass / Constants.BODY_DENSITY;
	}

	/**
	 * Two SimpleBody are colliding if the distance between their centers is
	 * less than the sum of their radius
	 */
	@Override
	public boolean intersect(SimpleBody body) {

		// Calculating the distance between bodies's centers
		double centersDistance = massCenter.distanceFrom(body.getMassCenter());

		// If this distance is less or equal than the sum of the radius, the
		// bodies are colliding
		if (centersDistance <= radius + body.radius - 2)
			return true;

		return false;
	}

	public double getRadius() {
		return radius;
	}
}
